﻿@model List<User>
@{
	ViewBag.Title = T("Manage users");
}
<ul class="path floatContainer">
	<li class="first">@Html.ActionLinkLocalized("Forums", "List", "Forums")</li>
	<li>@Html.ActionLinkLocalized("Admin", "Dashboard", "Admin")</li>
</ul>
<h1>@ViewBag.Title</h1>
@{Html.BeginForm(null, null, FormMethod.Get);}
<div class="formItem floatContainer">
	<label for="userName">@T("User name")</label>
	@Html.TextBox("userName")
</div>
<div class="formItem buttons floatContainer">
	<input type="submit" value="@T("Search")" />
</div>
@{Html.EndForm();}
@if (Model.Count > 0)
{
	var list = new PagedList<User>(this.Model, this.PageIndex, 100);
	using (Html.BeginForm(null, null, FormMethod.Post, new{@id="manageForm"}))
	{
		@Html.AntiForgeryToken()
		<input type="hidden" name="searched" value="@ViewBag.UserName" />
		<input type="hidden" name="id" id="userId" />
		<table cellpadding="0" cellspacing="5" class="admin">
			<thead>
				<tr>
					<th><span style="visibility:hidden;">@T("Action")</span></th>
					<th>@T("Name")</th>
					<th>@T("Role")</th>
					<th>@T("Registration date")</th>
				</tr>
			</thead>
			<tbody>
			@foreach (User u in list)
			{
				<tr>
					<td>
						<span class="actions">
							<a href="#" onclick="return promoteUser(@u.Id, '@u.UserName');">@T("Promote")</a>
							<a href="#" onclick="return demoteUser(@u.Id, '@u.UserName');">@T("Demote")</a>
							<a href="#" onclick="return deleteUser(@u.Id, '@u.UserName');">@T("Delete")</a>
						</span>
					</td>
					<td><strong>@u.UserName</strong></td>
					<td>@u.RoleName</td>
					<td>@Html.Date(u.RegistrationDate)</td>
				</tr>			
			}
			</tbody>
		</table>
	}
	@Html.Pager(list.PageSize, list.PageIndex, list.TotalItemCount, new{userName = ViewData.Get<string>("userName")}, S("Previous"), S("Next"))
	<script type="text/javascript">
		function deleteUser(userId, userName)
		{
			if (confirm('@T("Are you sure you want to DELETE the user {0}?")'.replace('{0}', userName)))
			{
				$("#userId").val(userId);
				$('#manageForm').attr('action', '@(Url.Action("Delete"))').submit();
			}
			return false;
		}
		function promoteUser(userId, userName) 
		{
			if (confirm('@T("Are you sure you want to Promote the user {0}?")'.replace('{0}', userName)))
			{
				$("#userId").val(userId);
				$('#manageForm').attr('action', '@(Url.Action("Promote"))').submit();
			}
			return false;
		}
		function demoteUser(userId, userName) 
		{
			if (confirm('@T("Are you sure you want to Demote the user {0}?")'.replace('{0}', userName)))
			{
				$("#userId").val(userId);
				$('#manageForm').attr('action', '@(Url.Action("Demote"))').submit();
			}
			return false;
		}
	</script>
}
else
{
	<p class="warning">@T("No user found for the username &quot;{0}&quot;.", ViewBag.UserName)</p>
}
